package net.cohoivang.admin;

import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;

import com.google.gson.JsonObject;

import net.cohoivang.core.*;
import net.cohoivang.news.NewsCategory;
import net.cohoivang.news.NewsDatabase;
import net.cohoivang.user.MyLanguages;
import net.cohoivang.web.GoldenAction;

public class CreateNews extends GoldenAction{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public String title;
	public String description;
	public String content;
	public String filePath;
	
	
	public String createBy;
	public String createDate;
	public String source;
	public String image;
	public int industry;
	public int sector;
	public int company;
	public int lang;	
	public int category;
	
	public long expiredTime;
	public int expiredDay;
	public float originalPrice;
	public float currentPrice;
	public float percentSafe;
	public float changePrice;
	public int isTop;
	public long currentTime;
	
	private List<Sector> listSector = new LinkedList<Sector>();
	
			
	public int getIndustry() {
		return industry;
	}

	public void setIndustry(int industry) {
		this.industry = industry;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	public String getCreateBy() {
		return createBy;
	}

	public void setCreateBy(String createBy) {
		this.createBy = createBy;
	}

	public String getCreateDate() {
		return createDate;
	}

	public void setCreateDate(String createDate) {
		this.createDate = createDate;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	public int getSector() {
		return sector;
	}

	public void setSector(int sector) {
		this.sector = sector;
	}

	public int getCompany() {
		return company;
	}

	public void setCompany(int company) {
		this.company = company;
	}

	public int getLang() {
		return lang;
	}

	public void setLang(int lang) {
		this.lang = lang;
	}

	public int getCategory() {
		return category;
	}

	public void setCategory(int category) {
		this.category = category;
	}

	public int getExpiredDay() {
		return expiredDay;
	}

	public void setExpiredDay(int expiredDay) {
		this.expiredDay = expiredDay;
	}

	public float getOriginalPrice() {
		return originalPrice;
	}

	public void setOriginalPrice(float originalPrice) {
		this.originalPrice = originalPrice;
	}

	public float getCurrentPrice() {
		return currentPrice;
	}

	public void setCurrentPrice(float currentPrice) {
		this.currentPrice = currentPrice;
	}

	public float getChangePrice() {
		return changePrice;
	}

	public void setChangePrice(float changePrice) {
		this.changePrice = changePrice;
	}

	public CreateNews(){
	}
	
	public List<Sector> getListSector() {
		return listSector;
	}

	public void setListSector(List<Sector> listSector) {
		this.listSector = listSector;
	}	
	
	public String createNewsJSP(){
		listSector = ProfileCompany.getInstance().getAllSector();
		System.out.print("get list sector\n");
		return SUCCESS;
	}
	
	public String doCreateNews() throws SQLException, ParseException{
		//new news always add top new list
		isTop = 0;
		//current time = system time
		currentTime = System.currentTimeMillis();
		//lang = 2 is vietnamese
		lang = 2;
		//expired Time = expired Day * hour * minutes * second
		expiredTime = expiredDay * 24 * 60 * 60;
		
		//change price and percent safe
		changePrice = originalPrice - currentPrice;
		percentSafe = changePrice*100/originalPrice;
		
		DateFormat formater = new SimpleDateFormat("dd/MM/yyyy");  
		java.util.Date parsedUtilDate = formater.parse(createDate);
		java.sql.Date sqltDate = new java.sql.Date(parsedUtilDate.getTime());
		
		int newId = NewsDatabase.getInstance().insertNews(category, title, description, content, filePath, sqltDate, createBy,
				sqltDate, createBy, source, image, industry, sector, company, lang, expiredTime,
				originalPrice, currentPrice, percentSafe, changePrice, isTop, currentTime);
		
		
		
		return SUCCESS;
	}
	
	@Override
	protected void fillActionJson(JsonObject mainJson) {
		// TODO Auto-generated method stub
		
	}	

}
